```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dubbo分布式服务框架详解 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        :root {
            --primary-color: #2563eb;
            --secondary-color: #1e40af;
            --accent-color: #3b82f6;
            --text-color: #1f2937;
            --light-text: #6b7280;
            --bg-color: #f9fafb;
            --card-bg: #ffffff;
            --border-color: #e5e7eb;
        }
        
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: var(--text-color);
            background-color: var(--bg-color);
            line-height: 1.6;
        }
        
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            margin-top: 1.5em;
            margin-bottom: 0.8em;
            color: var(--text-color);
        }
        
        h1 {
            font-size: 2.5rem;
            border-bottom: 2px solid var(--primary-color);
            padding-bottom: 0.5rem;
            margin-top: 0;
        }
        
        h2 {
            font-size: 1.8rem;
            color: var(--primary-color);
            position: relative;
            padding-left: 1rem;
        }
        
        h2:before {
            content: "";
            position: absolute;
            left: 0;
            top: 0.4em;
            height: 1em;
            width: 4px;
            background-color: var(--primary-color);
            border-radius: 2px;
        }
        
        h3 {
            font-size: 1.4rem;
            color: var(--secondary-color);
        }
        
        p {
            margin-bottom: 1.2em;
        }
        
        .hero {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            padding: 5rem 1rem;
            text-align: center;
            margin-bottom: 3rem;
            border-radius: 0 0 12px 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        .hero-title {
            font-size: 3.5rem;
            font-weight: 700;
            margin-bottom: 1rem;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }
        
        .hero-subtitle {
            font-size: 1.5rem;
            font-weight: 300;
            max-width: 800px;
            margin: 0 auto 2rem;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 1.5rem;
        }
        
        .card {
            background-color: var(--card-bg);
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            padding: 2rem;
            margin-bottom: 2rem;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            border-left: 4px solid var(--primary-color);
        }
        
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        
        .card-title {
            font-size: 1.5rem;
            color: var(--primary-color);
            margin-bottom: 1rem;
            display: flex;
            align-items: center;
        }
        
        .card-title i {
            margin-right: 0.8rem;
            color: var(--accent-color);
        }
        
        .image-container {
            margin: 2rem 0;
            text-align: center;
        }
        
        .image-container img {
            max-width: 100%;
            height: auto;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        .code-block {
            background-color: #1e293b;
            color: #e2e8f0;
            padding: 1.5rem;
            border-radius: 8px;
            font-family: 'Courier New', Courier, monospace;
            margin: 1.5rem 0;
            overflow-x: auto;
        }
        
        .code-block .keyword {
            color: #f472b6;
        }
        
        .code-block .string {
            color: #34d399;
        }
        
        .code-block .comment {
            color: #94a3b8;
            font-style: italic;
        }
        
        .code-block .annotation {
            color: #fbbf24;
        }
        
        .code-block .variable {
            color: #93c5fd;
        }
        
        .highlight {
            background-color: #fef08a;
            padding: 0.2rem 0.4rem;
            border-radius: 4px;
            color: #92400e;
        }
        
        .grid-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 2rem;
            margin: 2rem 0;
        }
        
        .feature-card {
            background-color: var(--card-bg);
            border-radius: 10px;
            padding: 1.5rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            transition: transform 0.3s ease;
            border-top: 3px solid var(--accent-color);
        }
        
        .feature-card:hover {
            transform: translateY(-5px);
        }
        
        .feature-icon {
            font-size: 2rem;
            color: var(--accent-color);
            margin-bottom: 1rem;
        }
        
        .footer {
            background-color: #1f2937;
            color: #f3f4f6;
            padding: 3rem 0;
            margin-top: 4rem;
        }
        
        .footer-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 1.5rem;
            text-align: center;
        }
        
        .footer-link {
            color: #93c5fd;
            text-decoration: none;
            transition: color 0.3s ease;
        }
        
        .footer-link:hover {
            color: #60a5fa;
            text-decoration: underline;
        }
        
        .timeline {
            position: relative;
            max-width: 800px;
            margin: 2rem auto;
        }
        
        .timeline:before {
            content: '';
            position: absolute;
            top: 0;
            left: 50%;
            width: 2px;
            height: 100%;
            background-color: var(--primary-color);
            transform: translateX(-50%);
        }
        
        .timeline-item {
            position: relative;
            margin-bottom: 2rem;
            width: 100%;
        }
        
        .timeline-item:nth-child(odd) {
            padding-right: calc(50% + 1.5rem);
            text-align: right;
        }
        
        .timeline-item:nth-child(even) {
            padding-left: calc(50% + 1.5rem);
            text-align: left;
        }
        
        .timeline-dot {
            position: absolute;
            top: 0;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: var(--primary-color);
            border: 3px solid white;
            box-shadow: 0 0 0 2px var(--primary-color);
        }
        
        .timeline-item:nth-child(odd) .timeline-dot {
            right: calc(50% - 11px);
        }
        
        .timeline-item:nth-child(even) .timeline-dot {
            left: calc(50% - 11px);
        }
        
        .timeline-content {
            background-color: white;
            padding: 1.5rem;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        .timeline-date {
            font-weight: bold;
            color: var(--primary-color);
            margin-bottom: 0.5rem;
        }
        
        .table-container {
            overflow-x: auto;
            margin: 2rem 0;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 1rem 0;
        }
        
        th, td {
            padding: 1rem;
            text-align: left;
            border-bottom: 1px solid var(--border-color);
        }
        
        th {
            background-color: var(--primary-color);
            color: white;
            font-weight: 600;
        }
        
        tr:nth-child(even) {
            background-color: rgba(59, 130, 246, 0.05);
        }
        
        tr:hover {
            background-color: rgba(59, 130, 246, 0.1);
        }
        
        @media (max-width: 768px) {
            .hero-title {
                font-size: 2.5rem;
            }
            
            .hero-subtitle {
                font-size: 1.2rem;
            }
            
            h1 {
                font-size: 2rem;
            }
            
            h2 {
                font-size: 1.5rem;
            }
            
            .timeline:before {
                left: 31px;
            }
            
            .timeline-item:nth-child(odd), 
            .timeline-item:nth-child(even) {
                padding-left: 4rem;
                padding-right: 1rem;
                text-align: left;
            }
            
            .timeline-item:nth-child(odd) .timeline-dot,
            .timeline-item:nth-child(even) .timeline-dot {
                left: 21px;
            }
        }
    </style>
</head>
<body>
    <div class="hero">
        <div class="container">
            <h1 class="hero-title">Dubbo分布式服务框架解析</h1>
            <p class="hero-subtitle">高性能RPC远程服务调用方案，构建高可用、高并发的分布式系统</p>
            <div class="flex justify-center space-x-4 mt-6">
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full"><i class="fas fa-bolt mr-2"></i>高性能</span>
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full"><i class="fas fa-network-wired mr-2"></i>分布式</span>
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full"><i class="fas fa-shield-alt mr-2"></i>高可用</span>
            </div>
        </div>
    </div>

    <div class="container">
        <section id="background">
            <h2><i class="fas fa-layer-group mr-2"></i>1. Dubbo背景与架构演进</h2>
            
            <div class="card">
                <h3 class="card-title"><i class="fas fa-cube"></i>1.1 单体架构</h3>
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1656128248310-209bc260-2fe4-4995-b54d-d769a142ff24.png" alt="单体架构示意图">
                </div>
                <p>当网站流量很小时，只需一个应用，将所有功能如下单支付等都部署在一起，以减少部署节点和成本。</p>
                
                <div class="mt-4 p-4 bg-red-50 rounded-lg border-l-4 border-red-500">
                    <h4 class="font-bold text-red-700 mb-2"><i class="fas fa-exclamation-triangle mr-2"></i>缺点</h4>
                    <ul class="list-disc pl-5 space-y-1">
                        <li>没有实现高可用，一旦服务器宕机就无法使用</li>
                        <li>每个业务模块耦合度很高，一个模块出问题会导致整个系统出现故障</li>
                        <li>承受不了高并发的请求</li>
                    </ul>
                </div>
            </div>
            
            <div class="card">
                <h3 class="card-title"><i class="fas fa-network-wired"></i>1.2 分布式/集群架构</h3>
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1656128248762-63dd2e5f-00d5-4651-9c53-1cb937a4b5a1.png" alt="分布式集群架构示意图">
                </div>
                <p><span class="highlight">分布式：</span>一个业务拆分为多个子业务，部署在多个服务器上。</p>
                <p><span class="highlight">集群：</span>同一个业务，部署在多个服务器上。</p>
                
                <div class="mt-4 bg-blue-50 p-4 rounded-lg">
                    <h4 class="font-bold text-blue-700 mb-2"><i class="fas fa-lightbulb mr-2"></i>1.2.1 举例说明分布式和集群的概念</h4>
                    <p>小饭店原来只有一个厨师，切菜洗菜备料炒菜全干。</p>
                    <p>后来客人多了，厨房一个厨师忙不过来，又请了个厨师，两个厨师都能炒一样的菜，两个厨师的关系是集群。</p>
                    <p>为了让厨师专心炒菜，把菜做到极致，再请了个配菜师负责切菜，备菜，备料... 厨师和配菜师的关系是分布式。</p>
                    <p>一个配菜师也忙不过来了，又请了个配菜师，两个配菜师关系是集群。</p>
                    <p>一个配菜师因故请假了，但是其余的配菜师还是该干啥就干啥，只是没请假的配菜师任务均匀的加量了，但他们的任务和职责是不变的，这是集群。</p>
                    <p class="font-bold text-blue-700 mt-2"><span class="highlight">集群：</span>多个人在一起作同样的事。</p>
                    <p class="font-bold text-blue-700"><span class="highlight">分布式：</span>多个人在一起作不同的事。</p>
                    <div class="image-container mt-4">
                        <img src="https://cdn.nlark.com/yuque/0/2022/jpeg/21449790/1656128249318-bf818ed8-3e7b-4b27-8125-0f51f09b5b9c.jpeg" alt="分布式与集群示例图">
                    </div>
                </div>
            </div>
            
            <div class="card">
                <h3 class="card-title"><i class="fas fa-code-branch"></i>1.3 表现层服务层分离</h3>
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1656128249789-d1e0a393-a095-47d0-8bdc-e6614d4a2211.png" alt="表现层服务层分离示意图">
                </div>
            </div>
            
            <div class="card">
                <h3 class="card-title"><i class="fas fa-clipboard-check"></i>1.4 总结</h3>
                <p>从单体架构到分布式演变就是为了解决单体架构的不足，从而得到达到以下三点：</p>
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4">
                    <div class="p-4 bg-green-50 rounded-lg">
                        <div class="flex items-center mb-2">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i>
                            <h4 class="font-bold">高可用</h4>
                        </div>
                        <p class="text-sm">系统部分故障不影响整体服务</p>
                    </div>
                    <div class="p-4 bg-blue-50 rounded-lg">
                        <div class="flex items-center mb-2">
                            <i class="fas fa-tachometer-alt text-blue-500 mr-2"></i>
                            <h4 class="font-bold">高并发</h4>
                        </div>
                        <p class="text-sm">支持大量用户同时访问</p>
                    </div>
                    <div class="p-4 bg-purple-50 rounded-lg">
                        <div class="flex items-center mb-2">
                            <i class="fas fa-puzzle-piece text-purple-500 mr-2"></i>
                            <h4 class="font-bold">松耦合</h4>
                        </div>
                        <p class="text-sm">模块之间依赖关系减少</p>
                    </div>
                </div>
                
                <div class="mermaid mt-6">
                    graph TD
                    A[单体架构] -->|问题: 单点故障| B[集群架构]
                    A -->|问题: 耦合度高| C[分布式架构]
                    B --> D[高可用]
                    C --> E[松耦合]
                    D --> F[分布式集群架构]
                    E --> F
                    F --> G[高并发]
                </div>
            </div>
        </section>
        
        <section id="introduction" class="mt-12">
            <h2><i class="fas fa-info-circle mr-2"></i>2. Dubbo简介</h2>
            
            <div class="card">
                <h3 class="card-title"><i class="fas fa-book-open"></i>2.1 Dubbo基本介绍</h3>
                <p>Dubbo是阿里巴巴旗下的一个分布式服务治理框架，致力于提供高性能和透明化的RPC远程服务调用方案，简单的说，dubbo就是个服务框架，如果没有分布式的需求，其实是不需要用的，只有在分布式的时候，才有dubbo这样的分布式服务框架的需求，并且本质上是个服务调用的技术，说白了就是个远程服务调用的分布式框架（告别Web Service模式中的WSdl，以服务者与消费者的方式在dubbo上注册）。</p>
            </div>
            
            <div class="card">
                <h3 class="card-title"><i class="fas fa-project-diagram"></i>2.2 Dubbo架构图</h3>
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1656128250386-b0fdf4bf-3bfc-4597-bb98-7ec5e57ad862.png" alt="Dubbo架构图">
                </div>
                
                <div class="mt-4">
                    <h4 class="font-bold text-gray-700 mb-2"><i class="fas fa-users mr-2"></i>节点角色说明：</h4>
                    <ul class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <li class="flex items-start">
                            <span class="inline-block bg-blue-100 text-blue-800 px-2 py-1 rounded mr-2">Provider</span>
                            <span>暴露服务的服务提供方</span>
                        </li>
                        <li class="flex items-start">
                            <span class="inline-block bg-green-100 text-green-800 px-2 py-1 rounded mr-2">Consumer</span>
                            <span>调用远程服务的服务消费方</span>
                        </li>
                        <li class="flex items-start">
                            <span class="inline-block bg-purple-100 text-purple-800 px-2 py-1 rounded mr-2">Registry</span>
                            <span>服务注册与发现的注册中心</span>
                        </li>
                        <li class="flex items-start">
                            <span class="inline-block bg-yellow-100 text-yellow-800 px-2 py-1 rounded mr-2">Monitor</span>
                            <span>统计服务的调用次调和调用时间的监控中心</span>
                        </li>
                        <li class="flex items-start">
                            <span class="inline-block bg-red-100 text-red-800 px-2 py-1 rounded mr-2">Container</span>
                            <span>服务运行容器</span>
                        </li>
                    </ul>
                </div>
                
                <div class="mt-6">
                    <h4 class="font-bold text-gray-700 mb-2"><i class="fas fa-exchange-alt mr-2"></i>调用关系说明：</h4>
                    <div class="timeline">
                        <div class="timeline-item">
                            <div class="timeline-dot"></div>
                            <div class="timeline-content">
                                <div class="timeline-date">步骤 0</div>
                                <p>服务容器负责启动，加载，运行服务提供者。</p>
                            </div>
                        </div>
                        <div class="timeline-item">
                            <div class="timeline-dot"></div>
                            <div class="timeline-content">
                                <div class="timeline-date">步骤 1</div>
                                <p>服务提供者在启动时，向注册中心注册自己提供的服务。</p>
                            </div>
                        </div>
                        <div class="timeline-item">
                            <div class="timeline-dot"></div>
                            <div class="timeline-content">
                                <div class="timeline-date">步骤 2</div>
                                <p>服务消费者在启动时，向注册中心订阅自己所需的服务。</p>
                            </div>
                        </div>
                        <div class="timeline-item">
                            <div class="timeline-dot"></div>
                            <div class="timeline-content">
                                <div class="timeline-date">步骤 3</div>
                                <p>注册中心返回服务提供者地址列表给消费者，如果有变更，注册中心将基于长连接推送变更数据给消费者。</p>
                            </div>
                        </div>
                        <div class="timeline-item">
                            <div class="timeline-dot"></div>
                            <div class="timeline-content">
                                <div class="timeline-date">步骤 4</div>
                                <p>服务消费者，从提供者地址列表中，基于软负载均衡算法，选一台提供者进行调用，如果调用失败，再选另一台调用。</p>
                            </div>
                        </div>
                        <div class="timeline-item">
                            <div class="timeline-dot"></div>
                            <div class="timeline-content">
                                <div class="timeline-date">步骤 5</div>
                                <p>服务消费者和提供者，在内存中累计调用次数和调用时间，定时每分钟发送一次统计数据到监控中心。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        
        <section id="features" class="mt-12">
            <h2><i class="fas fa-star mr-2"></i>3. Dubbo能做什么</h2>
            
            <div class="grid-container">
                <div class="feature-card">
                    <div class="feature-icon"><i class="fas fa-magic"></i></div>
                    <h3>透明化的远程方法调用</h3>
                    <p>就像调用本地方法一样调用远程方法，只需简单配置。</p>
                </div>
                <div class="feature-card">
                    <div class="feature-icon"><i class="fas fa-balance-scale"></i></div>
                    <h3>软负载均衡及容错机制</h3>
                    <p>可在内网替代负载均衡器服务器，降低成本，减少单点。</p>
                </div>
                <div class="feature-card">
                    <div class="feature-icon"><i class="fas fa-search-plus"></i></div>
                    <h3>服务自动注册与发现</h3>
                    <p>不再需要写死服务提供方地址，注册中心基于接口名查询服务提供者的IP地址，并且能够平滑添加或删除服务提供者。</p>
                </div>
            </div>
        </section>
        
        <section id="installation" class="mt-12">
            <h2><i class="fas fa-download mr-2"></i>4. Dubbo安装</h2>
            <div class="card">
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1656128250939-deb6452c-315c-4b95-90b9-e18948c02358.png" alt="Dubbo安装示意图">
                </div>
            </div>
        </section>
        
        <section id="integration" class="mt-12">
            <h2><i class="fas fa-plug mr-2"></i>5. SpringBoot整合Dubbo</h2>
            
            <div class="card">
                <h3 class="card-title"><i class="fas fa-cogs"></i>5.1 添加依赖</h3>
                <div class="code-block">
                    <pre><code>&lt;<span class="keyword">dependency</span>&gt;
    &lt;<span class="keyword">groupId</span>&gt;com.alibaba.boot&lt;/<span class="keyword">groupId</span>&gt;
    &lt;<span class="keyword">artifactId</span>&gt;dubbo-spring-boot-starter&lt;/<span class="keyword">artifactId</span>&gt;
    &lt;<span class="keyword">version</span>&gt;0.2.0&lt;/<span class="keyword">version</span>&gt;
&lt;/<span class="keyword">dependency</span>&gt;</code></pre>
                </div>
            </div>
            
            <div class="card">
                <h3 class="card-title"><i class="fas fa-server"></i>5.2 服务提供者</h3>
                
                <h4 class="font-bold text-gray-700 mt-4 mb-2"><i class="fas fa-code mr-2"></i>5.2.1 服务接口</h4>
                <div class="code-block">
                    <pre><code><span class="keyword">public interface</span> <span class="variable">IUserService</span> {
    <span class="keyword">public</span> List&lt;User&gt; getUserAll();
}</code></pre>
                </div>
                
                <h4 class="font-bold text-gray-700 mt-6 mb-2"><i class="fas fa-laptop-code mr-2"></i>5.2.2 服务实现类</h4>
                <div class="code-block">
                    <pre><code><span class="annotation">@com.alibaba.dubbo.config.annotation.Service</span> <span class="comment">// 发布服务要用dubbo下面的注解</span>
<span class="keyword">public class</span> <span class="variable">UserServieImpl</span> <span class="keyword">implements</span> <span class="variable">IUserService</span> {
    <span class="annotation">@Override</span>
    <span class="keyword">public</span> List&lt;User&gt; getUserAll() {
        System.<span class="variable">out</span>.println(<span class="string">"UserServieImpl.getUserAll 4 1 2"</span>);
        <span class="keyword">return</span> <span class="keyword">null</span>;
    }
}</code></pre>
                </div>
                
                <h4 class="font-bold text-gray-700 mt-6 mb-2"><i class="fas fa-sliders-h mr-2"></i>5.2.2 dubbo配置</h4>
                <div class="code-block">
                    <pre><code><span class="variable">spring.datasource.url</span>=<span class="string">jdbc:mysql://localhost:3306/1905_demo</span>
<span class="variable">spring.datasource.username</span>=<span class="string">root</span>
<span class="variable">spring.datasource.password</span>=<span class="string">root</span>
<span class="variable">spring.datasource.driver-class-name</span>=<span class="string">com.mysql.jdbc.Driver</span>

<span class="comment">#暴露的接口名称</span>
<span class="variable">dubbo.application.name</span>=<span class="string">user_service</span>

<span class="comment">#dubbo注册中心地址</span>
<span class="variable">dubbo.registry.address</span>=<span class="string">zookeeper://192.168.189.137:2181</span>

<span class="comment">#随机寻找一个可用端口</span>
<span class="variable">dubbo.protocol.port</span>=<span class="string">-1</span></code></pre>
                </div>
                
                <h4 class="font-bold text-gray-700 mt-6 mb-2"><i class="fas fa-rocket mr-2"></i>5.2.3 主启动类</h4>
                <div class="code-block">
                    <pre><code><span class="annotation">@SpringBootApplication</span>(scanBasePackages = <span class="string">"com.qf"</span>) <span class="comment">//暴露的服务要让dubbo扫到</span>
<span class="annotation">@DubboComponentScan</span>(basePackages = <span class="string">"com.qf.service.impl"</span>)
<span class="keyword">public class</span> <span class="variable">UserServiceUserApplication</span> {
    <span class="keyword">public static void</span> main(String[] args) {
        SpringApplication.<span class="variable">run</span>(UserServiceUserApplication.<span class="keyword">class</span>, args);
    }
}</code></pre>
                </div>
            </div>
            
            <div class="card mt-6">
                <h3 class="card-title"><i class="fas fa-laptop mr-2"></i>5.3 服务消费者</h3>
                
                <h4 class="font-bold text-gray-700 mt-4 mb-2"><i class="fas fa-code mr-2"></i>5.3.1 Controller中调用</h4>
                <div class="code-block">
                    <pre><code><span class="annotation">@Controller</span>
<span class="keyword">public class</span> <span class="variable">UserController</span> {
    <span class="annotation">@Reference</span>
    <span class="keyword">private</span> <span class="variable">IUserService</span> <span class="variable">userService</span>;
    
    <span class="annotation">@RequestMapping</span>(value = <span class="string">"/getUserList"</span>)
    <span class="keyword">public</span> String getUserList(Model model) <span class="keyword">throws</span> Exception {
        System.<span class="variable">out</span>.println(<span class="string">"UserController.getUserList"</span>);
        <span class="comment">//   userService.getUserAll();</span>
        <span class="keyword">return</span> <span class="string">"userList"</span>;
    }
}</code></pre>
                </div>
                <p class="mt-4"><span class="annotation">@Reference(url = "192.168.193.1:20880")</span> <span class="comment">// 直连</span></p>
                <p><span class="annotation">@Reference(loadbalance = "roundrobin")</span> <span class="comment">// 设置负载均衡规则</span></p>
                
                <h4 class="font-bold text-gray-700 mt-6 mb-2"><i class="fas fa-sliders-h mr-2"></i>5.3.1 服务消费者配置</h4>
                <div class="code-block">
                    <pre><code><span class="variable">spring.datasource.url</span>=<span class="string">jdbc:mysql://localhost:3306/1905_demo</span>
<span class="variable">spring.datasource.username</span>=<span class="string">root</span>
<span class="variable">spring.datasource.password</span>=<span class="string">root</span>
<span class="variable">spring.datasource.driver-class-name</span>=<span class="string">com.mysql.jdbc.Driver</span>

<span class="comment">## 消费者名称</span>
<span class="variable">dubbo.application.name</span>=<span class="string">user_web</span>

<span class="comment">#dubbo服务监控中心地址</span>
<span class="variable">dubbo.registry.address</span>=<span class="string">zookeeper://192.168.189.137:2181</span>

<span class="comment"># 关闭所有服务的启动时检查：(默认没有提供者时报错)  写在定义服务消费者一方</span>
<span class="variable">dubbo.consumer.check</span>=<span class="string">false</span>

<span class="comment">#调用服务超时时间</span>
<span class="variable">dubbo.consumer.timeout</span>=<span class="string">3000</span>

<span class="comment">#失败重试次数</span>
<span class="variable">dubbo.consumer.retries</span>=<span class="string">3</span></code></pre>
                </div>
            </div>
        </section>
        
        <section id="loadbalance" class="mt-12">
            <h2><i class="fas fa-weight-hanging mr-2"></i>6. Dubbo负载均衡策略</h2>
            <div class="card">
                <div class="grid-container">
                    <div class="feature-card">
                        <h3>随机模式</h3>
                        <p>按权重设置随机概率。在一个截面上碰撞的概率较高，但调用越大分布越均匀</p>
                    </div>
                    <div class="feature-card">
                        <h3>轮询模式</h3>
                        <p>按公约后的权重设置轮询比例。但存在响应慢的服务提供者会累积请求</p>
                    </div>
                    <div class="feature-card">
                        <h3>最少活跃调用数</h3>
                        <p>响应快的提供者接受越多请求，响应慢的接受越少请求</p>
                    </div>
                    <div class="feature-card">
                        <h3>一致hash</h3>
                        <p>根据服务提供者ip设置hash环，携带相同的参数总是发送的同一个服务提供者，若服务挂了，则会基于虚拟节点平摊到其他提供者上</p>
                    </div>
                </div>
                
                <div class="mt-6">
                    <h4 class="font-bold text-gray-700 mb-2"><i class="fas fa-lightbulb mr-2"></i>最少活跃调用数说明</h4>
                    <p>最少活跃调用数，相同活跃数的随机，活跃数指调用前后计数差。</p>
                    <p>使慢的提供者收到更少请求，因为越慢的提供者的调用前后计数差会越大。</p>
                </div>
            </div>
        </section>
    </div>
    
    <footer class="footer">
        <div class="footer-content">
            <h3 class="text-xl font-bold mb-2">技术小馆</h3>
            <p class="mb-4">分享前沿技术，探索编程之美</p>
            <a href="http://www.yuque.com/jtostring" class="footer-link">访问语雀主页</a>
        </div>
    </footer>
    
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```